//
// Created by 123 on 2024/12/31.
//
#include "iostream"
using namespace std;

class Person{
public:
    int age;
public:
    Person(){
        cout << "no param constructor" << endl;
    }
    Person(int a){
        age = a;
        cout << "param constructor" << endl;
    }
    //拷贝构造
    Person(const Person& person){
        age = person.age;
        cout << "copy constructor" << endl;
    }
    //析构
    ~Person(){
        cout << "destory" << endl;
    }
};

void test(){
    Person p;//调用无参构造
}
void test2(){
    Person p1(10);
    //无参构造不要加()
//    Person p2();
    //显示法
    Person p2 = Person(10);
    Person p3 = Person(p2);
    Person(10);//这是匿名对象，执行结束后马上就会析构
    //隐式法
    Person p4 = 10;//等价于 Person p4 = Person(10);
    Person p5 = p4;
    //不能利用拷贝构造初始化匿名对象，编译器会认为是对象声明
//    Person p5(p4);
}

int main58(){
//    test();
    test2();
    return 0;
}